# !/usr/local/bin/python3
# -*- encoding: utf-8 -*-
# @FileName :   CommonTypes.py
# @DateTime :   2022/8/25 | 13:15
# @Author   :   IoTus3
# @GitHub   :   https://gitee.com/IoTus3
# @Contact  :   xianglin.fu3@gmail.com
# @License  :   (C)Copyright 2022-2023, LinYuStudio-NLPR-CASIA
# @Editor   :   Power by PyCharm
# @Desc     :   通用库定义


# 导入库
import requests
# from fake_useragent import UserAgent
import json
from src.main.conf.conf import HEADER


# 通用Get请求, 不带参数
def send_request(url):
    # ua = UserAgent(verify_ssl=False)
    # header = {'User-Agent': ua.random}
    response = requests.get(url=url, headers=HEADER)
    response.encoding = response.apparent_encoding
    code = response.status_code
    if code != 200:
        print("请求失败，url： " + url + " 错误码： " + str(code))
    return response


# 通用Get请求带参数
def send_request_with_params(url, params):
    # ua = UserAgent(verify_ssl=False)
    # header = {'User-Agent': ua.random}
    response = requests.get(url=url, headers=HEADER, params=params)
    response.encoding = response.apparent_encoding
    code = response.status_code
    if code != 200:
        print("请求失败，url： " + url + " 错误码： " + str(code))
    return response


# 基本的post请求
def send_request_with_params_use_post(url, params):
    # ua = UserAgent(verify_ssl=False)
    # header = {'User-Agent': ua.random}
    response = requests.post(url=url, headers=HEADER, data=json.dumps(params))
    response.encoding = response.apparent_encoding
    code = response.status_code
    if code != 200:
        print("请求失败，url： " + url + " 错误码： " + str(code))
    return response
